<?php

namespace Beerus\Modules\DesignerAuth\Controllers;

use App\Http\Controllers\Controller;
use Doraemon\model\DesignerAuth;
use Doraemon\service\Designer\DesignerDingTalkAlert;
use Doraemon\service\DingTalkAlert;
use Doraemon\service\WechatAlert;
use Encore\Admin\Facades\Admin;
use Illuminate\Http\Request;

class AuditRemarkController extends Controller
{
	public function __construct()
	{
		parent::__construct();
		Admin::script('$(".pjax-container").attr("id","pjax-container");');
	}

	// 资料审核弹框页面
	public function remarkLayer($uid)
	{
		$auth_info = DesignerAuth::getByUId($uid);
		return view('DesignerAuth::audit.remark', [
			'uid' => $uid,
			'remark2' => $auth_info['remark2']
		]);
	}

	// 资料审核通过
	public function submit(Request $request)
	{
		$params = $request->all();

//		if (empty(trim($params['remark2']))) {
//			return response()->json(['msg' => '操作失败，请填写备注', 'code' => 0]);
//		}

		$admin_name = Admin::user()->username;
		$msg = implode("\n", [
			"操作：填写备注",
			"设计师uid：{$params['uid']}",
			"备注：{$params['remark2']}",
			"操作人：{$admin_name}\n",
		]);
        DesignerDingTalkAlert::sendBeerusDesignerAuthAuditMsg2Operator($params['uid'], $msg);

		$res = DesignerAuth::updateInfo($params['uid'], [
			'remark2' => $params['remark2']
		]);

		if (empty($res)) {
			return response()->json(['msg' => '操作失败，请稍后再尝试', 'code' => 0]);
		} else {
			return response()->json(['msg' => '操作成功', 'code' => 1]);
		}
	}
}
